﻿using System;

namespace Noea.TogSim.Model.Train.LocoDriver.States
{
    public class StoppingState : LocoState
    {
        public StoppingState()
            : base()
        {
            base._description = "Stopping";
        }
        public override LocoState Handle(LocoDriver_StPattern ld)
        {
            if (ld.Train.ActualSpeed > 0.2)
            {
                double acc = ld.Train.ActualSpeed / 2;
                ld.Train.Engine.Acceleration = (ld.Train.Deacceleration < acc) ? -ld.Deacceleration : -acc;
                return this;
            }
            else
            {
                ld.Train.Engine.Acceleration = 0.0;
                ld.Train.ActualSpeed = 0.0;
            }
            Console.WriteLine("Stopping returnerer {0}", ld.PreviousState.Description);
            return ld.PreviousState;
        }
    }
}
